'use strict';
require('./index.css');
require('page/common/header/index.js');
require('util/slider/index.js');
require('util/slider/index.js');

var _mm = require('util/mm.js');
var _default = require('service/default-service.js');
var templateBanner = require('./banner.string');
var templateIndex = require('./index.string');
var templatePxtonzhi = require('./pxtonzhi.string');
var templateTeacherlib = require('./teacherlib.string');
var templateCommunication = require('./communication.string')
var templateOnlineData = require('./onlineData.string')

var page = {

    init: function() {
        this.onLoad();
    },

    onLoad: function() {
        this.loadSilder();
        this.loadWorkTrend();
        this.loadPxtonzhi();
        this.loadTeacherlib();
        this.loadCommunication();
        this.loadOnlineData();
    },
    //加载工作动态
    loadWorkTrend: function() {
        var paymentHtml = "",
            _this = this,
            $pageWrap = $('.page-wrap');
        _default.getloadWorkTrend(function(res) {
            //渲染html
            paymentHtml = _mm.renderHtml(templateIndex, res);
            $pageWrap.html(paymentHtml);
        }, function(errMsg) {
            $pageWrap.html('<p class="err-tip>' + errMsg + '</p>"');
        });

    },
    loadPxtonzhi: function() {
        var paymentHtml = "",
            _this = this,
            $pageWrap = $('.pxtonzhi');
        _default.getNeedListTongzhi(function(res) {
            //渲染html
            paymentHtml = _mm.renderHtml(templatePxtonzhi, res);
            $pageWrap.html(paymentHtml);
        }, function(errMsg) {
            $pageWrap.html('<p class="err-tip>' + errMsg + '</p>"');
        });
    },
    loadTeacherlib: function() {
        var paymentHtml = "",
            _this = this,
            $pageWrap = $('.teacherlib');
        _default.getTeacherlibList(function(res) {
            //渲染html
            paymentHtml = _mm.renderHtml(templateTeacherlib, res);
            $pageWrap.html(paymentHtml);
        }, function(errMsg) {
            $pageWrap.html('<p class="err-tip>' + errMsg + '</p>"');
        });
    },
    loadCommunication: function() {
        var paymentHtml = "",
            _this = this,
            $pageWrap = $('.communication');
        _default.getCommunication(function(res) {
            //渲染html
            paymentHtml = _mm.renderHtml(templateCommunication, res);
            $pageWrap.html(paymentHtml);
        }, function(errMsg) {
            $pageWrap.html('<p class="err-tip>' + errMsg + '</p>"');
        });
    },
    loadOnlineData: function() {
        var paymentHtml = "",
            _this = this,
            $pageWrap = $('.onlineData');
        _default.getOnlineData(function(res) {
            //渲染html
            paymentHtml = _mm.renderHtml(templateOnlineData, res);
            $pageWrap.html(paymentHtml);
        }, function(errMsg) {
            $pageWrap.html('<p class="err-tip>' + errMsg + '</p>"');
        });
    },



    //加载轮播图
    loadSilder: function() {
        // 渲染banner的html
        var bannerHtml = _mm.renderHtml(templateBanner);
        $('.banner-con').html(bannerHtml);
        // 初始化banner
        var $slider = $('.banner').unslider({
            dots: true
        });
        // 前一张和后一张操作的事件绑定
        $('.banner-con .banner-arrow').click(function() {
            var forward = $(this).hasClass('prev') ? 'prev' : 'next';
            $slider.data('unslider')[forward]();
        });
    }
};

$(function() {
    page.init();
});